<?php
namespace app\common\tui;
class Order extends Push
{

    ##外卖提醒
    public function index($id){
        // $id = request()->param('id');
        $data = (new \app\common\model\Orders())->where(['id' => $id])->find();   
        $store = (new \app\common\model\Store())->where(['id' => $data['store_id']])->find();
    
        $mp3 = "";
        $state = 0;
        #您有新的订单请注意查收
        if($data['type'] == 1 && $data['state'] == 2){
            $mp3 = wconfig("STORE_AUDIO_1");
            $state = 1;

        }   
        #您有新的预定单请注意查收
        if($data['type'] == 2 && $data['state'] == 2){
            $mp3 = wconfig("STORE_AUDIO_2");
            $state = 2;
        }   

        #您有新的自取单请注意查收
        if($data['type'] == 3 && $data['state'] == 2){
            $mp3 = wconfig("STORE_AUDIO_3");
            $state = 3;
        } 
        
        #您有退款订单请注意查收
        if($data['state'] == 6){
            $mp3 = wconfig("STORE_AUDIO_4");
            $state = 4;
        }

        #您的订单即将超时请注意下处理
        if(($data['state'] == 2 || $data['state'] == 3) && $data['estimate_meal_time'] > time()){
            $mp3 = wconfig("STORE_AUDIO_5");
            $state = 5;
        }
        
        #以为您自动出餐
        if($data['store_state'] == 0 && !empty($store) && $store['is_eat_out_time'] == 1 && $data['store_state'] == 1){
            $mp3 = wconfig("STORE_AUDIO_6");
            $state = 6;
        }
      

        $params = [
            'cid' => request()->param('cid'),
            'title' => '标题',
            'content' => '介绍',
            'state' => $state,
            'mp3' => cdnurl($mp3,true),
        ];
        // var_dump($params);
         worker_url($params,'sendUser',$store['id'],'order_mp3','Worker');
        // var_dump($data);die;
        // var_dump($data);die;
        // return $this->push($params,'store');
    }
    public function rider($id = 201,$type = "order"){
        $mp3 = "";
        $state = 0;
        $type_arry = [
            'order' => '外卖', 'running' => '跑腿', 'buy' => '帮买',
        ];
        switch ($type) {
            case 'order':
                $order = (new \app\common\model\Orders())
                            ->append([
                                'pay_time_text',
                                'agent_name'
                                ])
                            ->where(['id' => $id])->find();
                if($order['state'] == 3){
                    $mp3 = wconfig("STORE_AUDIO_1"); #外卖订单
                    $state = 1;
                }  
                if($order['state'] == 6){
                    $mp3 = wconfig("STORE_AUDIO_4"); #退款
                    $state = 1;
                }  
                break;
            case 'running':
                $order = (new \app\common\model\RunningOrders())
                        ->append([
                            'pay_time_text',
                            'agent_name'
                        ])
                    ->where(['id' => $id])->find();
                if($order['order_status'] == 1){
                    $mp3 = wconfig("STORE_AUDIO_1"); #跑腿订单
                    $state = 1;
                }  
                if($order['order_status'] == 3){
                    $mp3 = wconfig("STORE_AUDIO_4"); #退款
                    $state = 1;
                }  
            break;
            case 'buy':
                $order = (new \app\common\model\BuyOrders())
                        ->append([
                            'pay_time_text',
                            'agent_name'
                        ])
                        ->where(['id' => $id])
                        ->find();
                if($order['order_status'] == 1){
                    $mp3 = wconfig("STORE_AUDIO_1"); #外卖订单
                    $state = 1;
                }  
                if($order['order_status'] == 3){
                    $mp3 = wconfig("STORE_AUDIO_4"); #退款
                    $state = 1;
                }  
                break;
        }
        if($state == 1){
            $params = [
                'order_id' => $order['id'],
                'title' => "您有新的{$type_arry[$type]}订单",
                'content' => '介绍',
                'state' => $state,
                'mp3' => cdnurl($mp3,true)."?=".time(),
                'order' => [
                    'pay_time_text' => $order['pay_time_text'],
                    'order_on' => $order['order_on'],
                    'agent_name' => $order['agent_name'],
                    'type' => $type,
                    'type_title' => $type_arry[$type],
                    'time_text' => date("Y-m-d H:i:s")
                ]
            ];
            // var_dump($params);
            // worker_url($params,'sendMessage',0,'order_mp3','RiderMp3');
            worker_url($params,'sendMessage',0,'order_mp3','RiderMp3');

        }
      
    }
}